#include<iostream>
using namespace std;
const int N = 1100000;
int a[N];
int lowbit(int i)
{
	return (-i) & i;
}
void add(int i, int x)
{
	for (; i <= N; i += lowbit(i))
	{
		a[i] += x;
	}
}
int sum(int i)
{
	int ans = 0;
	for (; i > 0; i -= lowbit(i))
		ans += a[i];
	return ans;
}
int main()
{
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++)
	{
		int x;
		cin >> x;
		add(i, x);
	}
	int m;
	cin >> m;
	while (m--)
	{
		int l, r;
		cin >> l >> r;
		printf("%d\n", sum(r) - sum(l - 1));
	}
}